t
Adding a Window

*26*The Folks Database is beginning to behave like a Macintosh application. But it needs a window to provide a means of interaction between the user and the application.

u
Select*296* Edit Application from the Exec menu.

u
Select the Windows radio button if it is not already selected. Select the Active List radio button.

u
Double-click the Window item in the Classes scrolling list to create a new Window class object. Creation of this object is confirmed with the Untitled entry in the List of Instances.

u
Click on the Untitled entry to select it and the List of Instances Scroll List, and then click on the*120* Edit button.

A small blank default window appears over the*42* Application editor*41* dialog. You turn this featureless window into a window that fits the design of your application by using Prograph’s*306* *1163*Window and*310* Window Item *1168* editors.

For your Folks Database application, the initial goal is to have a window that allows users to give a name to each new Person object they create. Your application window needs an editable text field where the name can be typed. The window also needs a simple button that, when pushed, creates and names a new Person object. 

Macintosh*122* button names usually suggest button function to users. This Folks Database application will keep track of a pool of people, and include each new Person object in the growing pool. So the button you later create can be an Add button.

Now that you have a good idea of what to put in this generic window instance to change it into your Folks Database application window, do the following:

u
Option-command-double-click anywhere within the window (except on its title bar). The Window editor pops up. Note that a default /Close method name has already been provided in the Close Method field.

u
Type Folks Database in the Window Title edit field, replacing the highlighted Untitled.

___________________________________________________________
NOTE: For now, you don’t need to worry about specifying Activate, Idle*717*, and Key *718*methods. The Activate *715*method is called when the window is brought to the top of a stack of windows. The Idle method is called when there is nothing else to do (that is, when no other events are being processed). The Key method is called when the user presses a key.

Also, for now accept the default document window-type radio button and the checked boxes selecting Close Box and Grow Box on this document window. If you do experiment with *1183*window types and attribute check boxes, use a Option-Command-double-click combination in the generic window to pop up the Window editor. You need to set your application window back to a document window with Close Box and Grow Box, to be consistent with the rest of the Grand Tour.
-----------------------------------------------------------

u
Press the OK button or press Return to dismiss the*1164**307* Window editor.

The window is now appropriately titled and ready for you to add the editable text field for entering new Person names wherever you want it located.

u
Position the crosshair cursor in the upper left corner of the Folks Database window. Command-drag a rectangular marquee about half an inch by two inches in size. Notice that a grabbing-hand cursor appears while you drag. Release the mouse button when the marquee looks about like this:

When you release the mouse button, the area within the marquee aligns to an invisible grid in the window. The bottom and right edges of the box are highlighted with thick solid lines, and a small square grow box is in the lower right corner. This rectangle is an unspecified Window Item instance. 

===========================================================
TIP: The Window editor maintains an invisible, eight-pixel grid for aligning objects in a window. You can override this default alignment by holding down the Option key while dragging the marquee.
===========================================================

Currently this box behaves much like a rectangle in a typical Macintosh graphics program. That is, it is an independent, resizable object. You can click-drag the lower right corner of this object to resize it.

Unlike a graphics-program object, however, this object can be easily transformed into one of the various types of objects that populate a Macintosh interface. It can become an edit-text field, a set of radio buttons, a scrolling list, a push button, an icon, a graphic, or a check box, among other interface objects. To turn this Window Item into an*290* Edit Text field:

u Double-click this new Window Item box to pop up the Window Item editor*299**1169*. This editor consists of a scrolling list of selections, which are the types of objects into which the Window Item instance can be turned.

___________________________________________________________
NOTE: The list in the*311* Window Item editor consists of the names of all the subclasses of the Window Item class in the System class hierarchy in the Classes window.
-----------------------------------------------------------

u
Click the Edit Text entry in the scrolling list.

u
Press the OK button or press Return. The Window Item editor dialog disappears, and the Edit Text editor pops up.

u
Type Name in the Name field.

u
Scroll the font list and click the Geneva item (or something similar to this)

u
Type 18 (or something else appropriate) in the Size box.

u
Click the Bold check box and accept the other instance attribute default values by pressing the OK button or by pressing Return.

The Edit Text editor disappears. The Edit Text item still looks a bit unusual because it is selected and the window is in edit mode. As soon as you begin to work on the Add button, the Edit Text item will take on its more familiar black box outline look.

u
Slightly below the Edit Text item, Command-drag a marquee about the size of the typical OK or Cancel button.

u
Double-click on this new Window Item object to pop up the Window Item editor.

u
Press OK or Return to accept the *263*default selection,*298* Button, in the editor’s scrolling list. The Window Item editor is replaced by the Button editor*121*.

u
Type Add in the Button Name field and press Tab.

u
Type Person/Add in the*166* Click Method field.

u
Press the OK button or press Return.

___________________________________________________________
NOTE: Window Items are added to the item list of a Window in the order in which they are created. If you want to make a particular button the default button (so that pressing Return is equivalent to clicking on the button), you must make the button the first item in the list. You can do this by*118* creating the default button first, or you can select the button and repeatedly choose*113**277* Bring Closer *595*from the Edit menu until the system beep tells you that the item has been brought to the front of the list. 
-----------------------------------------------------------

The*167* click method is the method that executes when the button is pressed. The default class of Window Item *1060**1173*is the Window class*1180* (similar to the default class of Menu Item being the Menu class). If you used a *232*data-determined *700*method reference, /Add, for the button’s click method, the Add method would need to be created in the Window *1057*class. Since Add creates a Person object, the explicit Person/Add specification is used to promote application-design clarity.

The design objective for the Add button is to have a click on it initiate the creation of a Person object. Further, its name attribute is to be set to the text string typed into the Edit Text field in the Folks Database window. To meet this initial objective, your Folks Database window now looks like this:

To see your Folks Database application in action, leave Application Builder and start your application running.

u
Click the close box of the Folks Database window.

u
Press Return to dismiss the Application editor.

u
Select Run initial in the Exec menu or press Command-R to start Folks Database running.

___________________________________________________________
NOTE: When you go to the Application editor, the application deactivates. You then have to do a Run initial from the Exec menu to resume execution.

If the window you just created does not appear along with your File menu, switch context and select Edit Application from the Exec menu to pull up the Application editor. Make sure that the Folks Database window is visible in the List of Instances scrolling list when you click the Active List radio button. If it is not, click the Library radio button, select the Folks Database item in the List of Instances and then click the Add to Active List button. You should now see your window when you again switch context.
-----------------------------------------------------------